<html>
<head>
<script>
var win_width = 620;
var win_height = 405;
window.resizeTo(win_width, win_height);
window.moveTo((screen.availWidth/2 - win_width/2), (screen.availHeight/2 - (win_height-27)/2));
</script>
<HTA:APPLICATION
  ID="oHTA"
  APPLICATIONNAME="Woorky 1.25"
  BORDER="thick"
  BORDERSTYLE="normal"
  SCROLL="no"
  SCROLLFLAT="yes"
  INNERBORDER="no"
  contextMenu="no"
  selection="no"
  SINGLEINSTANCE="yes"
  ICON="icon16.ico"
/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Woorky 1.25</title>
<script src="lib.js"></script>
<script>
var close_window = false;
function run_language_hta()
{
	close_window = true;
	window.close();
	shell.Run('mshta "'+realDir+'language.hta'+'"');
}
var language_file = realDir+'language.dat';
var default_language = '';
if (File.exists(language_file)) {
	default_language = File.read(language_file);
} else {
	run_language_hta();
}

var currencies = ['USD', 'EUR', 'GBP', 'PLN'];

var default_currency = '';
if ('en' == default_language) {
	default_currency = 'USD';
} else if ('pl' == default_language) {
	default_currency = 'PLN';
}

var language = '';
var lang = {};

function switch_lang(l, reload)
{
	if (language != l) {
		if (reload) {
			window.location.reload();
		}
	}
	language = l;
	var all_lang = {
		'add_task': {en: 'Add task', pl: 'Dodaj zadanie'},
		'options': {en: 'Options', pl: 'Opcje'},
		'manage_projects': {en: 'Manage projects', pl: 'Zarządzaj projektami'},
		'export_html': {en: 'Export to html', pl: 'Eksport do html'},
		'about_program': {en: 'About Woorky', pl: 'O programie'},
		'total_time': {en: 'Total time', pl: 'Czas razem'},
		'total_amount': {en: 'Total amount', pl: 'Kwota razem'},
		'day': {en: 'Day', pl: 'Dzień'},
		'time': {en: 'Time', pl: 'Czas'},
		'task': {en: 'Task', pl: 'Zadanie'},
		'action': {en: 'Action', pl: 'Akcja'},
		'rate': {en: 'Rate', pl: 'Stawka'},
		'add_project': {en: 'Add project', pl: 'Dodaj projekt'},
		'switch_panel': {en: 'Switch', pl: 'Przełącz'},
		'task_panel': {en: 'Tasks panel', pl: 'Panel zadań'},
		'currency': {en: 'Currency', pl: 'Waluta'},
		'add': {en: ' Add ', pl: 'Dodaj'},
		'edit': {en: ' Edit ', pl: 'Edytuj'},
		'delete': {en: 'Delete', pl: 'Usuń'},
		'cancel': {en: 'Cancel', pl: 'Anuluj'},
		'date': {en: 'Date', pl: 'Data'},
		'project': {en: 'Project', pl: 'Projekt'},
		'project_name_empty': {en: 'Project name is empty', pl: 'Wpisz nazwę projektu'},
		'invalid_rate': {en: 'Rate: invalid amount', pl: 'Stawka: nieprawidłowa wartość'},
		'only_one_project': {en: 'There is only one project, can\'t delete it', pl: 'Istnieje tylko jeden projekt, nie można go usunąć'},
		'project_delete_confirm': {en: 'Delete project?', pl: 'Na pewno usunąć projekt?'},
		'task_name_empty': {en: 'Task name is empty', pl: 'Wpisz nazwę zadania'},
		'invalid_time': {en: 'Invalid time format (ex. 2:30)', pl: 'Nieprawidłowy format czasu (np. 2:30)'},
		'task_delete_confirm': {en: 'Delete task?', pl: 'Na pewno usunąć zadanie?'},
		'change_language': {en: 'Change language', pl: 'Zmień język'},
		'no_tasks_found': {en: 'No tasks found', pl: 'Brak dodanych zadań'}
		//'': {en: '', pl: ''},
	};
	all_lang['about_html'] = {
		en: '<h1>About Woorky</h1><p>This program is free for private use.<br>Author: Cezary Tomczak (<a href="mailto:cagret@gmail.com">cagret@gmail.com</a>)<br>Latest version download from: <a target="_blank" href="http://code.gosu.pl">http://code.gosu.pl</a></p>',
		pl: '<h1>O programie</h1><p>Program jest darmowy do prywatnego użytku.<br>Autor: Cezary Tomczak (<a href="mailto:cagret@gmail.com">cagret@gmail.com</a>)<br>Najnowsza wersja do pobrania z: <a target="_blank" href="http://code.gosu.pl">http://code.gosu.pl</a></p>'
	};
	for (var i in all_lang) {
		lang[i] = all_lang[i][language];
	}
}
function switch_currency(c, reload)
{
	return;
	if (!c) {
		c = default_currency;
	}
	if ('PLN' == c) {
		//switch_lang('pl', reload);
	} else {
		//switch_lang('en', reload);
	}
	curr_currency = c;
}

switch_lang(default_language);

function write(s) { document.write(s); }
var options_timeout = null;
function options_over()
{
    if (options_timeout) {
        clearTimeout(options_timeout);
    }
    $('options').style.display = 'block';
	var pos = options_offset('options_link');
	$('options').style.top = (pos[1]+21)+'px';
	$('options').style.left = (pos[0]-12)+'px';
}
function options_out()
{
    if (options_timeout) {
        clearTimeout(options_timeout);
    }
    options_timeout = setTimeout(function(){
        $('options').style.display = 'none';
    }, 500);
}
function options_clear()
{
    if (options_timeout) {
        clearTimeout(options_timeout);
    }
    $('options').style.display = 'none';
}
function options_offset(el)
{
    el = document.getElementById(el);
    var x = 0, y = 0;
    do { if (el.nodeName.toLowerCase != 'td') { x += el.offsetLeft; y += el.offsetTop; }} while ((el = el.offsetParent) && el.nodeName.toLowerCase() != 'body');
    return [x,y];
}
</script>
<script src="task.js"></script>
<script src="project.js"></script>
<script src="main.js"></script>
<style type="text/css">@import url('style.css');</style>
</head>
<body>

<div id="tab_tasks_menu" class="top">
    <span id="select_project_container"><select id="select_project" onchange="project_load(this.value)"></select></span>
    &nbsp;&nbsp;

    <a href="#" onclick="task_new_show()"><script>write(lang.add_task);</script></a>
    &nbsp;&nbsp;<i>|</i>&nbsp;&nbsp;
    <a id="options_link" href="#" onmouseover="options_over()" onmouseout="options_out()"><script>write(lang.options);</script></a>

    <div onmouseover="options_over()" onmouseout="options_out()" id="options">
        <div><a href="#" onclick="options_clear(); tab_show('tab_projects');"><script>write(lang.manage_projects);</script></a></div>
        <div><a href="#" onclick="task_export()"><script>write(lang.export_html);</script></a></div>
		<div><a href="#" onclick="run_language_hta()"><script>write(lang.change_language);</script></a></div>
        <div><a href="#" onclick="tab_show('tab_info')"><script>write(lang.about_program);</script></a></div>
    </div>

    <span id="total_span"></span>
</div>

<div id="tab_projects_menu" class="top" style="display: none;">
    <a href="#" onclick="project_new_show()"><script>write(lang.add_project);</script></a>
    &nbsp;&nbsp;<i>|</i>&nbsp;&nbsp;
    <script>write(lang.switch_panel);</script>:&nbsp; <a href="#" onclick="tab_show('tab_tasks')"><script>write(lang.task_panel);</script> &gt;&gt;</a>
</div>

<div id="tab_info_menu" class="top" style="display: none;">
    <script>write(lang.switch_panel);</script>:&nbsp; <a href="#" onclick="tab_show('tab_tasks')"><script>write(lang.task_panel);</script> &gt;&gt;</a>
</div>

<div id="tab_tasks">

    <form onsubmit="return false;" id="form_task" style="display: none;">
	<table>
	<tr>
		<td valign="top">
			<table cellspacing="0" cellpadding="0">
			<tr>
				<td>
					<script>write(lang.day);</script>:&nbsp;
				</td>
				<td>
					<input type="text" id="task_new_day" value="" size="4">
				</td>
			</tr>
			<tr>
				<td>
					<script>write(lang.time);</script>:&nbsp;
				</td>
				<td>
					<input type="text" id="task_new_time" value="" size="4">
				</td>
			</tr>
			</table>
		</td>

		<td valign="top">
			<textarea cols="70" style="height: 46px;" id="task_new_name"></textarea>
		</td>
		<td valign="bottom" style="padding-bottom: 3px;">
			<span id="task_new_button">
				<input type="button" id="task_add_button" value="" class="submit" onclick="task_new()">
				&nbsp;<a href="#" onclick="task_new_cancel()"><script>write(lang.cancel);</script></a>
			</span>
			<span id="task_edit_span" style="display: none;">
				<input type="button" id="task_edit_button" value="" class="submit" onclick="task_edit()">
				&nbsp;<a href="#" onclick="task_edit_cancel()"><script>write(lang.cancel);</script></a>
				&nbsp;&nbsp;/&nbsp;&nbsp; <input type="button" id="task_delete_button" value="" class="submit" onclick="task_delete()">
			</span>
		</td>
	</tr>
	</table>
    </form>

    <div class="list">
        <div style="" id="tasks_div""></div>
    </div>

</div>

<div id="tab_projects" style="display: none;">

    <form onsubmit="return false;" id="form_project" style="display: none;">
        <script>write(lang.date);</script>:
        <input type="text" id="project_new_date" value="" size="10">
        <script>write(lang.project);</script>:
        <input type="text" size="25" id="project_new_name" value="">
        <script>write(lang.rate);</script>:
        <input type="text" id="project_new_rate" value="" size="3">
		<span id="project_new_currency_wrapper"><select id="project_new_currency"></select></span>
        <span id="project_new_button">
            <input type="button" id="project_add_button" value="" class="submit" onclick="project_new()">
            &nbsp;<a href="#" onclick="project_new_cancel()"><script>write(lang.cancel);</script></a>
        </span>
        <span id="project_edit_span" style="display: none;">
            <input type="button" id="project_edit_button" value="" class="submit" onclick="project_edit()">
            &nbsp;<a href="#" onclick="project_edit_cancel()"><script>write(lang.cancel);</script></a>
            &nbsp; <input type="button" id="project_delete_button" value="" class="submit" onclick="project_delete()">
        </span>
    </form>

    <div class="list">
        <div style="" id="projects_div""></div>
    </div>

</div>

<div id="tab_info" style="display: none;">
    <div style="margin: 1em;">
		<script>write(lang.about_html);</script>
    </div>
</div>

<script>
if (!close_window)
{
	setTimeout(function(){
		$('form_task').reset();
		$('form_project').reset();
		select_project_render();
		$('select_project').blur();
		$('task_add_button').value = lang.add;
		$('task_edit_button').value = lang.edit;
		$('task_delete_button').value = lang['delete'];
		$('project_add_button').value = lang.add;
		$('project_edit_button').value = lang.edit;
		$('project_delete_button').value = lang['delete'];
	},50);
	total_update();
	task_list();
	var __micro = time_start();
	setInterval('task_interval_sec()', 500);
}
</script>

</body>
</html>